package cc.smarnet.caihou.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cc.smarnet.caihou.R;
import cc.smarnet.caihou.entity.FlowerTagBook;

/**
* 入库信息的adapter
* */
public class TagBook2Adapter extends RecyclerView.Adapter {
    private Context context;
    private List<FlowerTagBook> list;

    public TagBook2Adapter(Context context, List<FlowerTagBook> list){
        this.context=context;
        this.list=list;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.boxes_print_list_item2,parent,false);
        ScanOutlistHolder warehouseViewHolder=new ScanOutlistHolder(view);
        return warehouseViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        FlowerTagBook flowerOutorderHZ = list.get(position);
        ScanOutlistHolder scanOutlistHolder = (ScanOutlistHolder) holder;
//        scanOutlistHolder.packingSpecifications.setText(flowerOutorderHZ.getPackingSpecifications());
//        scanOutlistHolder.storehouse.setText(flowerOutorderHZ.getStorehouse());
        scanOutlistHolder.variety.setText(flowerOutorderHZ.getVariety());
        scanOutlistHolder.classes.setText(flowerOutorderHZ.getClasses());
//        scanOutlistHolder.flowerPoleLength.setText(flowerOutorderHZ.getFlowerPoleLength());
        scanOutlistHolder.number.setText(flowerOutorderHZ.getNumber().toString());

    }

    @Override
    public int getItemCount() {
        // list.size()为0的话也必须至少返回1，返回有数值的话才会显示item，因为该方法不会返回0
        return list.size() > 0 ? list.size() : 1;
    }

    class ScanOutlistHolder extends RecyclerView.ViewHolder{
//        TextView packingSpecifications;
        TextView storehouse;
        TextView classes;
        TextView variety;
//        TextView flowerPoleLength;
        TextView number;

        public ScanOutlistHolder(@NonNull View itemView) {
            super(itemView);
//            packingSpecifications = itemView.findViewById(R.id.packingSpecifications);
//            storehouse = itemView.findViewById(R.id.storehouse);
            classes = itemView.findViewById(R.id.classes);
            variety = itemView.findViewById(R.id.variety);
//            flowerPoleLength = itemView.findViewById(R.id.flowerPoleLength);
            number = itemView.findViewById(R.id.number);

//            // item点击事件
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
//                    Warehouse warehouse=list.get(getAdapterPosition());
//                    Intent intent = new Intent(context, WarehouseDetailActivity.class);
//                    intent.putExtra("warehouseDetail", (Serializable) warehouse);
//                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
//                    context.startActivity(intent);
                }
            });
        }


    }
}
